import Block.*;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
/**
* Created with IntelliJ IDEA.
* User: Bram
* Date: 12-6-13
* Time: 12:54
* To change this template use File | Settings | File Templates.
*/
public class MineSweeperViewer extends JFrame {
boolean showRealtimeImage;
private BufferedImage emptyBlock, emptyFieldImage, bombBlock, flagBlock;
public MineSweeperViewer(final MineSweeper mineSweeper) {
super("Debug Viewer");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
try {
mineSweeper.update();
emptyFieldImage = mineSweeper.getImage();//ImageIO.read(new File("res", "EmptyField.png"));
emptyBlock = ImageIO.read(new File("res", "empty.png"));
bombBlock = ImageIO.read(new File("res", "bomb.png"));
flagBlock = ImageIO.read(new File("res", "flag.png"));
} catch (IOException e) {e.printStackTrace();}
JPanel jPanel = new JPanel(){
@Override
protected void paintComponent(Graphics g) {
if(showRealtimeImage)
g.drawImage(mineSweeper.getImage(), 0, 0, null);
else
g.drawImage(emptyFieldImage, 0, 0,null);
for(int c=0; c<mineSweeper.getBlocks().length; c++)
for(int r=0; r<mineSweeper.getBlocks()[0].length; r++) {
Block block = mineSweeper.getBlocks()[c][r];
if(block.getBlockNumber()!=null){
g.setColor(block.getBlockNumber().getColor());
g.drawString(""+block.getBlockNumber().getNumber(), block.x+4, block.y+12);
}
if(block.getBlockState()!=null)
switch(block.getBlockState()){
case FLAG: g.drawImage(flagBlock, block.x, block.y, null);
break;
case BOMB: g.drawImage(bombBlock, block.x, block.y, null);
break;
case EMPTY: if(block.getBlockNumber()==null)
g.drawImage(emptyBlock, block.x, block.y, null);
}
}
}
};
jPanel.setPreferredSize(new Dimension(emptyFieldImage.getWidth(), emptyFieldImage.getHeight()));
add(jPanel);
pack();
setVisible(true);
}
}